<?php

namespace App\Http\Requests\Order;

use App\Http\Requests\Request;

class OrderRequest extends Request
{
    /**
     * 验证通过
     *
     * @return bool
     */

    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     *
     * @return array
     */
    public function rules()
    {
        $rules['price'] = 'required';
        $rules['thumb'] = 'required';
        // 添加菜单
        if (request()->isMethod('POST')) {
            $rules['name'] = 'required|unique:products|max:10,name';
        }else{
            // 修改时 request()->method() 方法返回的是 PUT或PATCH
            $rules['name'] = 'required|max:10,name';
        }
        return $rules;
    }

    /**
     * 验证信息
     *
     * @return array
     */
    public function messages()
    {
        return [
            'required'=>trans('validation.required'),
            'max'=>trans('validation.max.numeric'),
            'unique'=>trans('validation.unique'),
        ];
    }

    /**
     * 字段名称
     * @return array
     */
    public function attributes()
    {
        return [
            'name'    => '名称',
            'price'  => '价格',
            'thumb'  => '缩略图',
        ];
    }
}
